package com.janko.springbootbase.controller;

import com.janko.springbootbase.entity.test.Student;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Author nyk
 * @Date 2021/3/10 15:06
 * @Version 1.0
 * @Desc
 */
public class TestStream {
    public static void main(String[] args) {
//        streamTest();
        System.out.println(comparedTotalPrice("23.01","23.00"));
    }
    private static boolean comparedTotalPrice(Object offer, String totalPrice) {
        BigDecimal d_offer=new BigDecimal(offer.toString());
        BigDecimal d_totalPrice=new BigDecimal(totalPrice);
        return d_offer.compareTo(d_totalPrice)==0;
    }

    private static void streamTest() {
        List<Student> list = new ArrayList<>();
        list.add(new Student("张三", 19, "男","98"));
        list.add(new Student("张三1", 19, "二斌","498"));
        list.add(new Student("张三2", 19, "二斌","198"));
        list.add(new Student("李四", 18, "男","38"));
        list.add(new Student("王五", 17, "男","998"));
        list.add(new Student("赵六", 16, "女","18"));
        list.add(new Student("周七", 15, "女","48"));
        list.add(new Student("吴八", 14, "女","68"));

        Map<String, Student> studentMap = list.parallelStream().collect(
                Collectors.groupingBy(Student::getSex, Collectors.collectingAndThen(Collectors.reducing((c1, c2) -> c1.getAge() > c2.getAge() ? c1 : c2), Optional::get)));
        for(Map.Entry<String,Student> entry:studentMap.entrySet()){
            System.out.println(entry.toString());
        }
    }
}
